import parole
from parole.colornames import colors
from parole.display import interpolateRGB
import pygame, random

import sim, sim_items, main, dungeon
from util import *

class Scroll(sim_items.Scroll):
    def __init__(self):
        sim_items.Scroll.__init__(self, "shining egress", "?", 
                ('light', 'go', 'far'),
                idDescription="Invoking the words of power in this scroll "\
                    "causes all stairs within one's vicinity to briefly "\
                    "glow. The color of this ghostly light depends on whether "\
                    "the stairs are ascending or descending.")

    def read(self, reader):
        rgbU = random.choice(['Red', 'Crimson', 'Pink', 'DeepPink'])
        rgbD = random.choice(['SpringGreen', 'Teal', 'Green', 'Lime'])
        self.uLight = parole.map.LightSource(colors[rgbU], 10.0)
        self.dLight = parole.map.LightSource(colors[rgbD], 10.0)

        self.map, self.upPos, self.downPos = main.levels[main.currentLevel]
        self.uLight.apply(self.map, self.upPos)
        self.dLight.apply(self.map, self.downPos)
        self.map.update()

        main.schedule.add(sim.Event('expire effect', main.schedule.time + 2*60000,
            (self,), dests=[self]))

        # identification
        if visible(self.upPos) or visible(self.downPos):
            main.player.identify(self)
        elif reader is main.player:
            main.transient("Nothing seems to happen.")

    def listen(self, event):
        sim_items.Scroll.listen(self, event)

        if event.id == 'expire effect' and event.args[0] is self:
            self.uLight.remove(self.map)
            self.dLight.remove(self.map)
            self.map.update()


#========================================
thingClass = Scroll
